import java.net.SocketException;
import java.util.Date;

import Interfaces.IAgentHandler;
import Interfaces.IDataHandler;
import Messages.DiscoveryMessage;
import Messages.MonitorDataTypeEnum;


public class AgentHandler implements IAgentHandler, IDataHandler
{

	@Override
	public void HandleNewAgent(DiscoveryMessage discMessage) 
	{
		System.out.println("Got discovery message ip " + discMessage.AgentIP + " host " + discMessage.AgentHost);
		
		try 
		{
			DataChannelListener dcl = new DataChannelListener(7000, this);
			dcl.startListening();
		} 
		catch (SocketException e) 
		{
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
		CommandChannel commandChannel = new CommandChannel();
		if (commandChannel.Register(discMessage.AgentIP, discMessage.AgentListeningPort, 7000, MonitorDataTypeEnum.CpuUsage, null))
			System.out.println("Monitor send register for cpu usage");
		
		
		
		//if(commandChannel.Unregister(discMessage.AgentIP, discMessage.AgentListeningPort, MonitorDataTypeEnum.CpuUsage))
		//	System.out.println("Monitor send unregister for cpu usage");
	}

	@Override
	public void HandleData(String agentIP, MonitorDataTypeEnum monitorDataType,
			Object[] parameters, Date timeStamp, String data) 
	{
		System.out.println("Got monitor data :)))");
		// TODO Auto-generated method stub
	}

}
